﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HRSystem.Entity;
using MySql.Data.MySqlClient;
using HRSystem.Utility;

namespace HRSystem.DBAccess
{
    public class BaseInfoAccess : Access
    {
        public Person GetPerson(int id)
        {
            string sql = string.Empty;
            if (id == 0)
                sql = "select * from person ";
            else
                sql = "select * from person where id=" + id;

            Person person = new Person();
            using (MySqlDataReader reader = MySqlUtil.GetDataReader(sql, null))
            {
                while (reader.Read())
                {
                    BaseInfo baseInfo = new BaseInfo();
                    baseInfo.ID = CheckIntNull(reader["id"]);
                    baseInfo.BaseChineseName = CheckNull(reader["base_chinese_name"]);
                    baseInfo.BaseEnglishName = CheckNull(reader["base_english_name"]);
                    baseInfo.BaseGender = CheckNull(reader["base_gender"]);
                    baseInfo.BaseHighestEducation = CheckNull(reader["base_highest_education"]);
                    baseInfo.BaseGraduatedSchool = CheckNull(reader["base_graduated_school"]);
                    baseInfo.BaseSpecialty = CheckNull(reader["base_specialty"]);
                    baseInfo.BaseBirthday = CheckDatetimeNull(reader["base_birthday"]);
                    baseInfo.BaseWorkExperienceYear = CheckIntNull(reader["base_work_experience_year"]);
                    baseInfo.BaseCurrentLocation = CheckNull(reader["base_current_location"]);
                    baseInfo.ExpandNationality = CheckNull(reader["expand_nationality"]);
                    baseInfo.ExpandNativePlace = CheckNull(reader["expand_native_place"]);
                    baseInfo.ExpandPoliticsFace = CheckNull(reader["expand_politics_face"]);
                    baseInfo.ExpandEthnic = CheckNull(reader["expand_ethnic"]);
                    baseInfo.ExpandMarryBirthBaby = CheckNull(reader["expand_marry_birth_baby"]);
                    baseInfo.ExpandHealth = CheckNull(reader["expand_health"]);
                    baseInfo.ExpandBloodType = CheckNull(reader["expand_blood_type"]);
                    baseInfo.ExpandHobby = CheckNull(reader["expand_hobby"]);
                    //OperateProcessRecode
                    baseInfo.IsDataCollect = Convert.ToBoolean(CheckIntNull(reader["is_data_collect"]));
                    baseInfo.DataCollectCertificate = CheckNull(reader["data_collect_certificate"]);
                    baseInfo.IsEducationSurvey = Convert.ToBoolean(CheckIntNull(reader["is_education_survey"]));
                    baseInfo.EducationSurveyOperatePerson = CheckNull(reader["education_survey_operate_person"]);
                    baseInfo.EducationSurveyOrganization = CheckNull(reader["education_survey_organization"]);
                    baseInfo.EducationSurveyResult = CheckNull(reader["education_survey_result"]);
                    baseInfo.IsSurvey = Convert.ToBoolean(CheckIntNull(reader["is_survey"]));
                    baseInfo.SurveyTime = CheckDatetimeNull(reader["survey_time"]);
                    baseInfo.SurveyOperatePerson = CheckNull(reader["survey_operate_person"]);
                    baseInfo.SurveyWorkTruth = CheckNull(reader["survey_work_truth"]);
                    baseInfo.SurveyEveryTruth = CheckNull(reader["survey_every_truth"]);
                    baseInfo.SurveyExceptionRemark = CheckNull(reader["survey_exception_remark"]);

                    person.myBaseInfo = baseInfo;

                    ResumeLabel resumeLabel = new ResumeLabel();
                    resumeLabel.ResumeKeyword = CheckNull(reader["resume_keyword"]);
                    resumeLabel.ResumeSource = CheckNull(reader["resume_source"]);
                    resumeLabel.ResumeGetTime = CheckDatetimeNull(reader["resume_get_time"]);
                    person.myResumeLabel = resumeLabel;

                    ContactWay contactWay = new ContactWay();
                    contactWay.ContactMobilePhone = CheckNull(reader["contact_mobile_phone"]);
                    contactWay.ContactEmail = CheckNull(reader["contact_email"]);
                    contactWay.ContactQQMSNICQNumber = CheckNull(reader["contact_qq_msn_icq_number"]);
                    contactWay.ContactAddress = CheckNull(reader["contact_address"]);
                    person.myContactWay = contactWay;

                    PhoneTalkRecord phoneTalkRecord = new PhoneTalkRecord();
                    phoneTalkRecord.RecordTime = CheckDatetimeNull(reader["record_time"]);
                    phoneTalkRecord.RecordPerson = CheckNull(reader["record_person"]);
                    phoneTalkRecord.RecordFamily = CheckNull(reader["record_family"]);
                    phoneTalkRecord.RecordCharacter = CheckNull(reader["record_character"]);
                    phoneTalkRecord.RecordCommunication = CheckNull(reader["record_communication"]);
                    phoneTalkRecord.JobWish = CheckNull(reader["job_wish"]);
                    phoneTalkRecord.JobDepartureReason = CheckNull(reader["job_departure_reason"]);
                    phoneTalkRecord.JobTargetPosition = CheckNull(reader["job_target_position"]);
                    phoneTalkRecord.SalarPresent = CheckDoubleNull(reader["salary_present"]);
                    phoneTalkRecord.SalarTarget = CheckDoubleNull(reader["salary_target"]);
                    phoneTalkRecord.SpecialIssue = CheckNull(reader["special_issue"]);
                    phoneTalkRecord.AuditionTime = CheckNull(reader["audition_time"]);
                    phoneTalkRecord.IsAcceptSurvey = Convert.ToBoolean(CheckIntNull(reader["is_accept_survey"]));
                    person.myPhoneTalkRecord = phoneTalkRecord;

                }
            }
            return person;
        }

        public List<BaseInfo> GetBaseInfo(Person person)
        {
            string sql = @"select* from person as A
                                     left join resume as B on(A.id=B.person_id)
                                     left join operation_record as C on(A.id=C.person_id)
                                     left join result as D on(A.id=D.person_id) where 1=1";

            string sqlChineseName = GetLikeSQLStr("a.base_chinese_name", person.myBaseInfo.BaseChineseName);//中文姓名
            string sqlBaseEnglishName = GetLikeSQLStr("A.base_english_name", person.myBaseInfo.BaseEnglishName);//英文姓名
            string sqlBaseGender = GetLikeSQLStr("A.base_gender", person.myBaseInfo.BaseGender);//性别
            string sqlBaseHighestEducation = GetLikeSQLStr("A.base_highest_education", person.myBaseInfo.BaseHighestEducation);//最高学历
            string sqlBaseGraduatedSchool = GetLikeSQLStr("A.base_graduated_school", person.myBaseInfo.BaseGraduatedSchool); //毕业学校
            string sqlBaseSpecialty = GetLikeSQLStr("A.base_specialty", person.myBaseInfo.BaseSpecialty);//专业
            //string sqlBaseAge = GetLikeSQLStr("A.base_age", person.myBaseInfo.BaseAge.ToString()); //年龄
            //string sqlBaseWorkExperienceYear = GetLikeSQLStr("A.base_work_experience_year", person.myBaseInfo.BaseWorkExperienceYear.ToString());//工作经验（年）
            string sqlBaseCurrentLocation = GetLikeSQLStr("A.base_current_location", person.myBaseInfo.BaseCurrentLocation); //现在所在地
            string sqlExpandNativePlace = GetLikeSQLStr("A.expand_native_place", person.myBaseInfo.ExpandNativePlace);//籍贯
            string sqlExpandMarryBirthBaby = GetLikeSQLStr("A.expand_health", person.myBaseInfo.ExpandMarryBirthBaby);//政治面貌
            string sqlResumeKeyword = GetLikeSQLStr("A.expand_native_place", person.myResumeLabel.ResumeKeyword);//简历关键词

            string sqlEducationSchoolName = GetLikeSQLStr("B.education_school_name", person.myResume.EducationSchoolName);//学校名称
            string sqlEducationSchoolCharacter = GetLikeSQLStr("B.education_school_character", person.myResume.EducationSchoolCharacter);//学校性质
            string sqlEducationSpecialty = GetLikeSQLStr("B.education_specialty", person.myResume.EducationSpecialty); //专业
            string sqlEducationdDgree = GetLikeSQLStr("B.education_dgree", person.myResume.EducationdDgree);//学历/学位
            string sqlWorkCompany = GetLikeSQLStr("B.work_company", person.myResume.WorkCompany);//供职单位/公司
            string sqlWorkPosition = GetLikeSQLStr("B.work_position", person.myResume.WorkPosition); //职位
            string sqlRelevanceCredentials = GetLikeSQLStr("B.education_dgree", person.myResume.RelevanceCredentials);//（职称、资质、技能证书）

            string sqlPhoneOperatePerson = GetLikeSQLStr("C.phone_operate_person", person.myOperateProcessRecode.PhoneOperatePerson);//电话访谈操作人
            string sqlRecommenOperatePerson = GetLikeSQLStr("C.recommen_operate_person", person.myOperateProcessRecode.RecommenOperatePerson); //简历推荐操作人
            string sqlRecommenCompany = GetLikeSQLStr("C.recommen_company", person.myOperateProcessRecode.RecommenCompany);//推荐单位/公司
            string sqlInterviewOperatePerson = GetLikeSQLStr("C.interview_operate_person", person.myOperateProcessRecode.InterviewOperatePerson);//面试操作人
            string sqlInterviewPerson = GetLikeSQLStr("C.interview_person", person.myOperateProcessRecode.InterviewPerson); //面试官
            string sqlInterviewCompany = GetLikeSQLStr("C.interview_company", person.myOperateProcessRecode.InterviewCompany);//面试单位/公司\

            string sqlEmployCompany = GetLikeSQLStr("D.employ_company", person.myResultRecord.EmployCompany);//录用公司
            string sqlEmployDepartment = GetLikeSQLStr("D.employ_department", person.myResultRecord.EmployDepartment); //录用单位
            string sqlEmployPosition = GetLikeSQLStr("D.employ_position", person.myResultRecord.EmployPosition);//录用岗位

            sql = string.Concat(sql, sqlChineseName, sqlBaseEnglishName, sqlBaseGender, sqlBaseHighestEducation, sqlBaseGraduatedSchool,
                                                sqlBaseSpecialty, sqlBaseCurrentLocation, sqlExpandNativePlace,
                                                sqlExpandMarryBirthBaby, sqlResumeKeyword,

                                                sqlEducationSchoolName, sqlEducationSchoolCharacter, sqlEducationSpecialty, sqlEducationdDgree,
                                                sqlWorkCompany, sqlWorkPosition, sqlRelevanceCredentials,

                                                sqlPhoneOperatePerson, sqlRecommenOperatePerson, sqlRecommenCompany, sqlInterviewOperatePerson,
                                                sqlInterviewPerson, sqlInterviewCompany,

                                                sqlEmployCompany, sqlEmployDepartment, sqlEmployPosition
                                            );

            sql += " group by A.id";
            List<BaseInfo> list = new List<BaseInfo>();
            using (MySqlDataReader reader = MySqlUtil.GetDataReader(sql, null))
            {
                while (reader.Read())
                {
                    BaseInfo baseInfo = new BaseInfo();
                    baseInfo.ID = CheckIntNull(reader["id"]);
                    baseInfo.BaseChineseName = CheckNull(reader["base_chinese_name"]);
                    baseInfo.BaseEnglishName = CheckNull(reader["base_english_name"]);
                    baseInfo.BaseGender = CheckNull(reader["base_gender"]);
                    baseInfo.BaseHighestEducation = CheckNull(reader["base_highest_education"]);
                    baseInfo.BaseGraduatedSchool = CheckNull(reader["base_graduated_school"]);
                    baseInfo.BaseSpecialty = CheckNull(reader["base_specialty"]);
                    baseInfo.BaseBirthday = CheckDatetimeNull(reader["base_birthday"]);
                    baseInfo.BaseWorkExperienceYear = CheckIntNull(reader["base_work_experience_year"]);
                    baseInfo.BaseCurrentLocation = CheckNull(reader["base_current_location"]);
                    baseInfo.ExpandNationality = CheckNull(reader["expand_nationality"]);
                    baseInfo.ExpandNativePlace = CheckNull(reader["expand_native_place"]);
                    baseInfo.ExpandPoliticsFace = CheckNull(reader["expand_politics_face"]);
                    baseInfo.ExpandEthnic = CheckNull(reader["expand_ethnic"]);
                    baseInfo.ExpandMarryBirthBaby = CheckNull(reader["expand_marry_birth_baby"]);
                    baseInfo.ExpandHealth = CheckNull(reader["expand_health"]);
                    baseInfo.ExpandBloodType = CheckNull(reader["expand_blood_type"]);
                    baseInfo.ExpandHobby = CheckNull(reader["expand_hobby"]);
                    list.Add(baseInfo);
                }
            }
            return list;
        }

        public bool AddOrUpdateBaseInfo(BaseInfo baseInfo)
        {
            bool bNew = false;
            if (baseInfo.ID == 0)
            {
                bNew = true;
            }

            string sql = string.Empty;
            MySqlParameter[] myParams;

            if (bNew)
            {
                sql = @"insert person(base_chinese_name,base_english_name,base_gender,base_highest_education,
                                base_graduated_school,base_specialty,base_birthday,base_work_experience_year,
                                base_current_location,expand_nationality,expand_native_place,expand_politics_face,expand_ethnic,
                                expand_marry_birth_baby,expand_health ,expand_blood_type,expand_hobby) values(
                                ?base_chinese_name,?base_english_name,?base_gender,?base_highest_education,
                                ?base_graduated_school,?base_specialty,?base_birthday,?base_work_experience_year,
                                ?base_current_location,?expand_nationality,?expand_native_place,?expand_politics_face,?expand_ethnic,
                                ?expand_marry_birth_baby,?expand_health ,?expand_blood_type,?expand_hobby)";
                myParams = new MySqlParameter[]{
                    new MySqlParameter("?base_chinese_name",baseInfo.BaseChineseName),
                    new MySqlParameter("?base_english_name",baseInfo.BaseEnglishName),
                    new MySqlParameter("?base_gender",baseInfo.BaseGender),
                    new MySqlParameter("?base_highest_education",baseInfo.BaseHighestEducation),
                    new MySqlParameter("?base_graduated_school",baseInfo.BaseGraduatedSchool),
                    new MySqlParameter("?base_specialty",baseInfo.BaseSpecialty),
                    new MySqlParameter("?base_birthday",baseInfo.BaseBirthday),
                    //new MySqlParameter("?base_age",baseInfo.BaseAge),
                    new MySqlParameter("?base_work_experience_year",baseInfo.BaseWorkExperienceYear),
                     new MySqlParameter("?base_current_location",baseInfo.BaseCurrentLocation),
                    new MySqlParameter("?expand_nationality",baseInfo.ExpandNationality),
                    new MySqlParameter("?expand_native_place",baseInfo.ExpandNativePlace),
                    new MySqlParameter("?expand_politics_face",baseInfo.ExpandPoliticsFace),
                    new MySqlParameter("?expand_ethnic",baseInfo.ExpandEthnic),
                    new MySqlParameter("?expand_marry_birth_baby",baseInfo.ExpandMarryBirthBaby),
                    new MySqlParameter("?expand_health",baseInfo.ExpandHealth),
                    new MySqlParameter("?expand_blood_type",baseInfo.ExpandBloodType),
                    new MySqlParameter("?expand_hobby",baseInfo.ExpandHobby)
                };
            }
            else
            {
                sql = @"update person set  base_chinese_name=?base_chinese_name,base_english_name=?base_english_name,
                                base_gender=?base_gender,base_highest_education=?base_highest_education,
                                base_graduated_school=?base_graduated_school,base_specialty=?base_specialty,
                                base_birthday=?base_birthday,base_work_experience_year=?base_work_experience_year,
                                base_current_location=?base_current_location,expand_nationality=?expand_nationality,
                                expand_native_place=?expand_native_place,expand_politics_face=?expand_politics_face,
                                expand_ethnic=?expand_ethnic,expand_marry_birth_baby=?expand_marry_birth_baby,
                                expand_health=?expand_health ,expand_blood_type=?expand_blood_type,
                                expand_hobby=?expand_hobby where id=?id";
                myParams = new MySqlParameter[]{
                    new MySqlParameter("?base_chinese_name",baseInfo.BaseChineseName),
                    new MySqlParameter("?base_english_name",baseInfo.BaseEnglishName),
                    new MySqlParameter("?base_gender",baseInfo.BaseGender),
                    new MySqlParameter("?base_highest_education",baseInfo.BaseHighestEducation),
                    new MySqlParameter("?base_graduated_school",baseInfo.BaseGraduatedSchool),
                    new MySqlParameter("?base_specialty",baseInfo.BaseSpecialty),
                    new MySqlParameter("?base_birthday",baseInfo.BaseBirthday),
                    //new MySqlParameter("?base_age",baseInfo.BaseAge),
                    new MySqlParameter("?base_work_experience_year",baseInfo.BaseWorkExperienceYear),
                     new MySqlParameter("?base_current_location",baseInfo.BaseCurrentLocation),
                    new MySqlParameter("?expand_nationality",baseInfo.ExpandNationality),
                    new MySqlParameter("?expand_native_place",baseInfo.ExpandNativePlace),
                    new MySqlParameter("?expand_politics_face",baseInfo.ExpandPoliticsFace),
                    new MySqlParameter("?expand_ethnic",baseInfo.ExpandEthnic),
                    new MySqlParameter("?expand_marry_birth_baby",baseInfo.ExpandMarryBirthBaby),
                    new MySqlParameter("?expand_health",baseInfo.ExpandHealth),
                    new MySqlParameter("?expand_blood_type",baseInfo.ExpandBloodType),
                    new MySqlParameter("?expand_hobby",baseInfo.ExpandHobby),
                    new MySqlParameter("?id",baseInfo.ID),
                };
            }

            if (MySqlUtil.ExecuteNonQuery(sql, myParams) == -1)
            {
                return false;
            }

            baseInfo.ID = bNew ? GetLastID("person") : baseInfo.ID;
            return true;
        }

        public bool UpdateDataCollect(BaseInfo baseInfo)
        {
            MySqlParameter[] myParams;
            string sql = @"update person set is_data_collect=?is_data_collect,data_collect_certificate=?data_collect_certificate where id=?id";
            myParams = new MySqlParameter[]{
                    new MySqlParameter("?is_data_collect",baseInfo.IsDataCollect),
                    new MySqlParameter("?data_collect_certificate",baseInfo.DataCollectCertificate),
                    new MySqlParameter("?id",baseInfo.ID)
                };
            if (MySqlUtil.ExecuteNonQuery(sql, myParams) == -1)
            {
                return false;
            }

            return true;
        }

        public bool UpdateEducationSurvey(BaseInfo baseInfo)
        {
            MySqlParameter[] myParams;
            string sql = @"update person set education_survey_operate_person=?education_survey_operate_person,
                                      education_survey_organization=?education_survey_organization,
                                      education_survey_result=?education_survey_result where id=?id";
            myParams = new MySqlParameter[]{
                    new MySqlParameter("?is_education_survey",baseInfo.IsEducationSurvey),
                    new MySqlParameter("?education_survey_operate_person",baseInfo.EducationSurveyOperatePerson),
                    new MySqlParameter("?education_survey_organization",baseInfo.EducationSurveyOrganization),
                    new MySqlParameter("?education_survey_result",baseInfo.EducationSurveyResult),
                    new MySqlParameter("?id",baseInfo.ID)
                };
            if (MySqlUtil.ExecuteNonQuery(sql, myParams) == -1)
            {
                return false;
            }

            return true;
        }

        public bool UpdateSurvey(BaseInfo baseInfo)
        {
            MySqlParameter[] myParams;
            string sql = @"update person set is_survey=?is_survey,survey_time=?survey_time,
                                     survey_operate_person=?survey_operate_person,survey_work_truth=?survey_work_truth,
                                     survey_every_truth=?survey_every_truth,survey_exception_remark=?survey_exception_remark where id=?id";
            myParams = new MySqlParameter[]{
                    new MySqlParameter("?is_survey",baseInfo.IsSurvey),
                    new MySqlParameter("?survey_time",baseInfo.SurveyTime),
                    new MySqlParameter("?survey_operate_person",baseInfo.SurveyOperatePerson),
                    new MySqlParameter("?survey_work_truth",baseInfo.SurveyWorkTruth),
                    new MySqlParameter("?survey_every_truth",baseInfo.SurveyEveryTruth),
                    new MySqlParameter("?survey_exception_remark",baseInfo.SurveyExceptionRemark),
                    new MySqlParameter("?id",baseInfo.ID)
                };
            if (MySqlUtil.ExecuteNonQuery(sql, myParams) == -1)
            {
                return false;
            }

            return true;
        }

        public bool AddOrUpdateResumeLabel(ResumeLabel resumeLabel)
        {
            bool bNew = false;
            if (resumeLabel.ID == 0)
            {
                bNew = true;
            }

            string sql = string.Empty;
            MySqlParameter[] myParams;

            if (bNew)
            {
                sql = @"insert person(resume_keyword,resume_source,resume_get_time) values(
                                ?resume_keyword,?resume_source,?resume_get_time)";
                myParams = new MySqlParameter[]{
                    new MySqlParameter("?resume_keyword",resumeLabel.ResumeKeyword),
                    new MySqlParameter("?resume_source",resumeLabel.ResumeSource),
                    new MySqlParameter("?resume_get_time",resumeLabel.ResumeGetTime)
                };
            }
            else
            {
                sql = @"update person set  resume_keyword=?resume_keyword,resume_source=?resume_source,
                                resume_get_time=?resume_get_time where id=?id";
                myParams = new MySqlParameter[]{
                    new MySqlParameter("?resume_keyword",resumeLabel.ResumeKeyword),
                    new MySqlParameter("?resume_source",resumeLabel.ResumeSource),
                    new MySqlParameter("?resume_get_time",resumeLabel.ResumeGetTime),
                    new MySqlParameter("?id",resumeLabel.ID)
                };
            }

            if (MySqlUtil.ExecuteNonQuery(sql, myParams) == -1)
            {
                return false;
            }

            resumeLabel.ID = bNew ? GetLastID("person") : resumeLabel.ID;
            return true;
        }

        public bool AddOrUpdateContactWay(ContactWay contactWay)
        {
            bool bNew = false;
            if (contactWay.ID == 0)
            {
                bNew = true;
            }

            string sql = string.Empty;
            MySqlParameter[] myParams;

            if (bNew)
            {
                sql = @"insert person(contact_mobile_phone,contact_email,contact_qq_msn_icq_number,contact_address) values(
                                ?contact_mobile_phone,?contact_email,?contact_qq_msn_icq_number,?contact_address)";
                myParams = new MySqlParameter[]{
                    new MySqlParameter("?contact_mobile_phone",contactWay.ContactMobilePhone),
                    new MySqlParameter("?contact_email",contactWay.ContactEmail),
                    new MySqlParameter("?contact_qq_msn_icq_number",contactWay.ContactQQMSNICQNumber),
                    new MySqlParameter("?contact_address",contactWay.ContactAddress)
                };
            }
            else
            {
                sql = @"update person set  contact_mobile_phone=?contact_mobile_phone,contact_email=?contact_email,
                                contact_qq_msn_icq_number=?contact_qq_msn_icq_number,contact_address=?contact_address where id=?id";
                myParams = new MySqlParameter[]{
                    new MySqlParameter("?contact_mobile_phone",contactWay.ContactMobilePhone),
                    new MySqlParameter("?contact_email",contactWay.ContactEmail),
                    new MySqlParameter("?contact_qq_msn_icq_number",contactWay.ContactQQMSNICQNumber),
                    new MySqlParameter("?contact_address",contactWay.ContactAddress),
                    new MySqlParameter("?id",contactWay.ID)
                };
            }

            if (MySqlUtil.ExecuteNonQuery(sql, myParams) == -1)
            {
                return false;
            }

            contactWay.ID = bNew ? GetLastID("person") : contactWay.ID;
            return true;
        }

        public bool AddOrUpdatePhoneTalkRecord(PhoneTalkRecord phoneTalkRecord)
        {
            bool bNew = false;
            if (phoneTalkRecord.ID == 0)
            {
                bNew = true;
            }

            string sql = string.Empty;
            MySqlParameter[] myParams;

            if (bNew)
            {
                sql = @"insert person(record_time,record_person,record_family,record_character,record_communication,job_wish,
                            job_departure_reason,job_target_position,salary_present,salary_target,special_issue,audition_time,
                            is_accept_survey) values(
                            ?record_time,?record_person,?record_family,?record_character,?record_communication,?job_wish,
                            ?job_departure_reason,?job_target_position,?salary_present,?salary_target,?special_issue,?audition_time,
                            ?is_accept_survey)";
                myParams = new MySqlParameter[]{
                    new MySqlParameter("?record_time",phoneTalkRecord.RecordTime),
                    new MySqlParameter("?record_person",phoneTalkRecord.RecordPerson),
                    new MySqlParameter("?record_family",phoneTalkRecord.RecordFamily),
                    new MySqlParameter("?record_character",phoneTalkRecord.RecordCharacter),
                    new MySqlParameter("?record_communication",phoneTalkRecord.RecordCommunication),
                    new MySqlParameter("?job_wish",phoneTalkRecord.JobWish),
                    new MySqlParameter("?job_departure_reason",phoneTalkRecord.JobDepartureReason),
                    new MySqlParameter("?job_target_position",phoneTalkRecord.JobTargetPosition),
                    new MySqlParameter("?salary_present",phoneTalkRecord.SalarPresent),
                    new MySqlParameter("?salary_target",phoneTalkRecord.SalarTarget),
                    new MySqlParameter("?special_issue",phoneTalkRecord.SpecialIssue),
                    new MySqlParameter("?audition_time",phoneTalkRecord.AuditionTime),
                    new MySqlParameter("?is_accept_survey",phoneTalkRecord.IsAcceptSurvey)
                };
            }
            else
            {
                sql = @"update person set  record_time=?record_time,record_person=?record_person,record_family=?record_family,
                            record_character=?record_character,record_communication=?record_communication,job_wish=?job_wish,
                            job_departure_reason=?job_departure_reason,job_target_position=?job_target_position,salary_present=?salary_present,
                            salary_target=?salary_target,special_issue=?special_issue,audition_time=?audition_time,
                            is_accept_survey=?is_accept_survey where id=?id";
                myParams = new MySqlParameter[]{
                    new MySqlParameter("?record_time",phoneTalkRecord.RecordTime),
                    new MySqlParameter("?record_person",phoneTalkRecord.RecordPerson),
                    new MySqlParameter("?record_family",phoneTalkRecord.RecordFamily),
                    new MySqlParameter("?record_character",phoneTalkRecord.RecordCharacter),
                    new MySqlParameter("?record_communication",phoneTalkRecord.RecordCommunication),
                    new MySqlParameter("?job_wish",phoneTalkRecord.JobWish),
                    new MySqlParameter("?job_departure_reason",phoneTalkRecord.JobDepartureReason),
                    new MySqlParameter("?job_target_position",phoneTalkRecord.JobTargetPosition),
                    new MySqlParameter("?salary_present",phoneTalkRecord.SalarPresent),
                    new MySqlParameter("?salary_target",phoneTalkRecord.SalarTarget),
                    new MySqlParameter("?special_issue",phoneTalkRecord.SpecialIssue),
                    new MySqlParameter("?audition_time",phoneTalkRecord.AuditionTime),
                    new MySqlParameter("?is_accept_survey",phoneTalkRecord.IsAcceptSurvey),
                    new MySqlParameter("?id",phoneTalkRecord.ID)
                };
            }

            if (MySqlUtil.ExecuteNonQuery(sql, myParams) == -1)
            {
                return false;
            }

            phoneTalkRecord.ID = bNew ? GetLastID("person") : phoneTalkRecord.ID;
            return true;
        }

        private string GetLikeSQLStr(string tableColumnName, string value)
        {
            return value == string.Empty ? string.Empty : " and " + tableColumnName + " like '%" + value + "%'";
        }
    }
}
